package com.mradio.app.security;

import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.authentication.dao.AbstractUserDetailsAuthenticationProvider;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.userdetails.UserDetails;

public class ApplicationAuthenticationProvider extends
		AbstractUserDetailsAuthenticationProvider {

	@Override
	protected void additionalAuthenticationChecks(UserDetails arg0,
			UsernamePasswordAuthenticationToken arg1)
			throws AuthenticationException {
		// TODO Auto-generated method stub

	}

	@Override
	protected UserDetails retrieveUser(String username,
			UsernamePasswordAuthenticationToken authentication)
			throws AuthenticationException {
//		String password = (String) authentication.getCredentials();
//        if (!StringUtils.hasText(password)) {
//            throw new BadCredentialsException("Please enter password");
//        }
//        List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
//        try {
//        	//FIXME
////            Speaker speaker = Speaker.findSpeakersByEmailAndPasswordEquals(username, \
////password).getSingleResult();
//        	
//            authorities.add(new GrantedAuthorityImpl("ROLE_USER"));
//        } catch (EmptyResultDataAccessException e) {
//            throw new BadCredentialsException("Invalid username or password");
//        } catch (EntityNotFoundException e) {
//            throw new BadCredentialsException("Invalid user");
//        } catch (NonUniqueResultException e) {
//            throw new BadCredentialsException("Non-unique user, contact administrator");
//        }
//        return new User(username, password, true, // enabled
//                true, // account not expired
//                true, // credentials not expired
//                true, // account not locked
//                authorities);
		
		// FIXME 2012-02-09 KP
		return null;
	}
}
